<?php
    if(file_exists("../bussiness/MenuBR.php")){
        include_once("../bussiness/MenuBR.php");
    }elseif(file_exists("bussiness/MenuBR.php")){
        include_once("bussiness/MenuBR.php");
    }
    if(file_exists("../entity/Opcion.php")){
        include_once ("../entity/Opcion.php");
    }elseif(file_exists("entity/Opcion.php")){
        include_once ("entity/Opcion.php");
    }
    if(file_exists("../entity/Constantes.php")){
        include_once ("../entity/Constantes.php");
    }elseif(file_exists("entity/Constantes.php")){
        include_once ("entity/Constantes.php");
    }
    
    $usuario = $_SESSION[Constantes::K_SESSION_CODIGO_USUARIO];
    echo cargarMenu($usuario);
    
    function cargarMenu($usuario){
        $menu = new MenuBR();
        $result = $menu->cargarMenu($usuario);
        
        $html = "<ul>";
        $html.= "<li class='active'><a href='index.php'><span>TICKET</span></a></li>";
        
        if(sizeof($result)){
            foreach ($result as $res){
                if($res->nivel == 1){
                    $nivel1[] = $res;
                }
                if($res->nivel == 2){
                    $nivel2[] = $res;
                }
                if($res->nivel == 3){
                    $nivel3[] = $res;
                }
            }
        }
        $c1 = 0;$c2 = 0;
        
        foreach ($nivel1 as $n1){
            $ul="";
            $cul="";
            $html2="";
            foreach ($nivel2 as $n2){
                if($n1->codigo == $n2->dependencia){
                    $href="?set=".$n2->codigo;
                    $html2.="<li><a href='".$href."'><span>".$n2->nombre_opcion."</span></a></li>";
                    $c1++;
                }
            }
            $class = "active";
            if($c1>0){
                $class = "has-sub";
                $ul="<ul>";
                $cul="</ul>";
            }
            $html.="<li class='".$class."'><a href='#'><span>".$n1->nombre_opcion."</span></a>";
            $html.=$ul.$html2.$cul;
            $html.="</li>";
            $c1=0;
        }
        $html.= "</ul>";
        return $html;
    }
?>
<head>
    <script src="../extensions/jquery-ui-1.10.4/js/jquery-1.10.2.js"></script>
    <script src="../extensions/jquery-ui-1.10.4/js/jquery-ui-1.10.4.custom.js"></script>
    <link rel="stylesheet" href="../css/SGSI.css">
    <script type='text/javascript' src='../js/menu_jquery.js'></script>
</head>